﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sqlserverdemo.entitys
{
    public class TUser
    {
        // 私有字段示例（可选）
        //private long _id;
        //private string _name;
        //private int _age;
        //private string _mail;
        //private string _sex;
        //private string _addr;
        //private string _phone;


        // 自动属性示例
        public long? Id
        {
            get;
            set;
        }

        public string? Name
        {
            get;
            set;
        }

        public int? Age
        {
            get;
            set;
        }

        public string? Mail
        {
            get;
            set;
        }

        public string? Sex
        {
            get;
            set;
        }

        public string? Addr
        {
            get;
            set;
        }

        public string? Phone
        {
            get;
            set;
        }

        public long? DeptId { get; set; }
        public TDept? Dept { get; set; }

        public ICollection<TAddr>? Addrs { get; set; }  // 导航属性
        public ICollection<TRole>? Roles { get; set; }  // 多对多导航属性
        public override string ToString()
        {
            return $"Id: {Id}, Name: {Name}, Age: {Age},Sex:{Sex}, Mail: {Mail},Addr:{Addr}";
        }
    }

    public class TAddr
    {
        private long _id;
        private string _addr;
        private long _userId;
        private TUser _user;

        public long Id
        {
            get => _id;
            set => _id = value;
        }
        public string Addr
        {
            get => _addr;
            set => _addr = value;
        }
        public long UserId
        {
            get => _userId;
            set => _userId = value;
        }

        public TUser User
        {
            get => _user;
            set => _user = value;
        }

        public override string ToString()
        {
            return $"Id: {Id}, Addr: {Addr}";
        }
    }


    public class TRole
    {
        private long _id;
        private string _name;
        public long Id
        {
            get => _id;
            set => _id = value;
        }
        public string Name
        {
            get => _name;
            set => _name = value;
        }

        public ICollection<TUser> Users { get; set; }  // 多对多导航属性

        public override string ToString()
        {
            return $"Id: {Id}, Name: {Name}";
        }
    }

    // 部门
    public class TDept
    {
        private long _id;
        private string _name;
        private string _addr;
        public long Id
        {
            get => _id;
            set => _id = value;
        }
        public string Name
        {
            get => _name;
            set => _name = value;
        }
        public string Addr
        {
            get => _addr;
            set => _addr = value;
        }

        public TUser User { get; set; }

        public override string ToString()
        {
            return $"Id: {Id}, Name: {Name}, Addr: {Addr}";
        }
    }
}
